﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
using System.Xml;
using System.Data.SqlClient;
using System.Data.Sql;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;


namespace MysqlTest
{

    public class Order 
    {
        [Key]
        public int OrderID { get; set; }
        public string CustomerName { get; set; }
        public List<OrderDetail> OrderDetailsList { get { return itemlist; } set { itemlist = value; } }
        [NotMapped]
        public int Sum
        {
            get
            {
                int S = 0;
                foreach (OrderDetail temp in this.OrderDetailsList)
                {
                    S += temp.ProductNumber * temp.Value;
                }
                return S;
            }
            set
            {
                foreach (OrderDetail temp in this.OrderDetailsList)
                {
                    Sum += temp.ProductNumber * temp.Value;
                }
            }

        }
        private List<OrderDetail> itemlist = new List<OrderDetail>();
        public Order(int orderID, string customerID, List<OrderDetail> list)
        {
            this.OrderID = orderID;
            this.CustomerName = customerID;
            foreach (OrderDetail temp in list)
            {
                    this.OrderDetailsList.Add(temp);
            }
        }
        public Order() { }


        public override string ToString()
        {
            return "ID：" + OrderID + " 总价：" + Sum + " 客户：" + CustomerName;
        }

        public override bool Equals(object obj)
        {
            Order m = obj as Order;
            return m.OrderID == this.OrderID && m != null;
        }
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
